import path from 'path'
import Koa from 'koa'
import KoaRouter from 'koa-router'
import KoaBodyParser from 'koa-bodyparser'
import KoaStatic from 'koa-static'

import equipment from './router/equipment'
import aqi from './router/aqi'
import weather from './router/weather'

const app = new Koa()
const router = new KoaRouter()

/**
 * @api {get} /test 接口测试
 * @apiName GetTest
 * @apiGroup Test
 * @apiDescription 用于测试服务器启动是否正常
 *
 * @apiSuccess {String} msg 测试成功
 */

router
  // 测试路由
  .get('/test', ctx => {
    ctx.body = {
      msg: '测试成功',
    }
  })
  .use('/equipment', equipment)
  .use('/aqi', aqi)
  .use('/weather', weather)

app
  .use(KoaStatic(path.join(__dirname, '../public')))
  .use(KoaBodyParser())
  .use(router.routes())
  .use(router.allowedMethods())

export default app
